package com.eascs.admin.o2o.cacle.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.eascs.admin.o2o.backfee.service.O2OComBankFeeService;
import com.eascs.admin.o2o.cacle.entity.O2oCacleFlowEntity;
import com.eascs.admin.o2o.cacle.service.O2oCacleFlowServiceImpl;
import com.eascs.admin.o2o.internal.util.BaseUtils;
import com.eascs.admin.o2o.loan.entity.O2oLoanUserEntity;
import com.eascs.admin.o2o.loan.entity.O2oLoanapplyEntity;
import com.eascs.admin.o2o.loan.service.O2oLoanUserService;
import com.eascs.admin.o2o.loan.service.O2oLoanapplyService;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.site.controller.BaseRestController;
import com.eascs.site.view.BaseRestResult;
import com.eascs.site.view.HtmlRestResult;
import com.eascs.site.view.ViewContext;

@RestController
@RequestMapping("/cacler")
public class O2oCacleRestController extends BaseRestController {

	@Autowired
	O2OComBankFeeService o2oComBankFeeService;
	@Autowired
	private O2oLoanapplyService o2oLoanapplyService;

	@Autowired
	private O2oCacleFlowServiceImpl o2oCacleFlowServiceImpl;
	@Autowired
	private O2oLoanUserService o2oLoanUserService;
	
	@Autowired
	private BaseUtils baseUtils;
	
	private static Logger log = LoggerFactory.getLogger(O2oCacleRestController.class);

	/**
	 * @Title: detail
	 * @Description: 作废详情页
	 * @author 余勇
	 * @param id
	 * @return
	 * @return BaseRestResult<String>
	 * @throws
	 * @date 2018年1月19日 上午10:07:32
	 */
	@RequestMapping("/detail")
	public BaseRestResult<String> detail(String id){
		
		O2oCacleFlowEntity o2oCacleFlowEntity = o2oCacleFlowServiceImpl.getEntityById(id);
		
		O2oLoanapplyEntity loan = o2oLoanapplyService.findById(o2oCacleFlowEntity.getLoanapplyNo());
		
		O2oLoanUserEntity loanUser = o2oLoanUserService.findById(loan.getLoanId(), loan.getLoanapplyNo());
		
		ViewContext.put("o2oCacleFlowEntity", o2oCacleFlowEntity);
		ViewContext.put("o2oLoanUserEntityZx", loanUser);
		String agreeUrl = baseUtils.getApprovalAgreeUrl(id, null, "PROCESS_CACLE");
		ViewContext.put("agreeUrl", agreeUrl);

		return HtmlRestResult.popHtmlFragment("cacle/cacle_detail");
	}
	
}
